<style>
#ul_pic_list li{margin: 5px;list-style-type:none}
#old_pic_list li{float: left; width:150px;height: 150px;margin: 5px;list-style-type: none}
ul {list-style:none;margin-left:-40px}
</style>
<div class="tab-div">
<div id="tabbar-div">
    <p>
    <p>
        <span class="tab-front" >通用信息</span>
        <span class="tab-back" >商品描述</span>
        <span class="tab-back" >会员价格</span>
        <span class="tab-back" >商品属性</span>
        <span class="tab-back" >商品相册</span>
    </p>
    </p>
</div>
<div id="tabbody-div">
    <form enctype="multipart/form-data" action="__ACTION__" method="post">
        <input type="hidden" name="id" value="{$row.id}" />
        <table width="90%" class="tab_table" align="center">
            <tr>
                <td class="label3">商品名称：</td>
                <td><input type="text" name="goods_name" value="{$row['goods_name']}"size="30" />
                <span class="require-field">*</span></td>
            </tr>
            <tr>
                <td class="label3">商品货号： </td>
                <td>
                    <input type="text" name="goods_sn" value="{$row.goods_sn}" size="20"/>
                    <span id="goods_sn_notice"></span><br />
                    <span class="notice-span"id="noticeGoodsSN">如果您不输入商品货号，系统将自动生成一个唯一的货号。</span>
                </td>
            </tr>
            <tr>
                <td class="label3">商品分类：</td>
                <td>
                    <select name="cat_id">
                        <option value="0">选择分类...</option>
                        <?php foreach ($cateData as $k =>$v):
                        if($v['id'] == $row['cat_id'])
                        $select ='selected = "selected"';
                        else
                        $select = "";
                        ?>
                        <option value="{$v.id}"
                        <?php echo $select;?> ><?php echo str_repeat('-',8*$v['level']) . $v[cate_name]?></option>
                        <?php endforeach?>
                    </select>
                    <span class="require-field">*</span>
                </td>
            </tr>
            <tr>
                <td class="label3">商品品牌：</td>
                <td>
                    <?php buildSelect('brand','brand_id','id','brand_name',$row['brand_id']); ?>
                </td>
            </tr>
            <tr>
                <td class="label3">扩展分类:
                    <input onclick="addNewCat()" type="button" id="btn_add_cat" value="添加一个"/>
                </td>
                <td>
                    <ul id="cat_list">
                        <?php if($gcData): ?>
                        <?php foreach ($gcData as $k1 => $v1): ?>
                        <li>
                            <select name="ext_cat_id[]">
                                <option value="">扩展分类...</option>
                                <?php foreach ($cateData as $k =>$v):
                                if($v['id'] == $v1['cat_id'])
                                $select = 'selected = "selected "';
                                else $select = '';
                                ?>
                                <option <?php echo $select; ?> value ="{$v.id}"><?php echo str_repeat('-',8*$v['level']) . $v[cate_name]?></option>
                                <?php endforeach; ?>
                            </select>
                        </li>
                        <?php endforeach; ?>
                        <?php else: ?>
                        <li>
                            <select name="cat_id">
                                <option value="0">选择分类...</option>
                                <?php foreach ($cateData as $k =>$v): ?>
                                <option <?php echo $select;?> value="{$v.id}">
                                <?php echo str_repeat('-',8*$v['level']) . $v[cate_name]?>
                                </option>
                                <?php endforeach?>
                            </select>
                        </li>
                        <?php endif; ?>
                    </ul>
                </td>
            </tr>
            <tr>
                <td class="label3">本店售价：</td>
                <td>
                    <input type="text" name="shop_price" value="{$row.shop_price}" size="20"/>
                    <span class="require-field">*</span>
                </td>
            </tr>
                <td class="label3">是否上架：</td>

                <td>
                    <input type="radio" name="is_on_sale" value="Y" <if condition="$row.is_on_sale eq Y"> checked </if> /> 是
                    <input type="radio" name="is_on_sale" value="N" <if condition="$row.is_on_sale eq N"> checked </if> /> 否
                </td>
            </tr>
            <tr>
                <td class="label3">促销价格：</td>
                <td>
                    价格￥:<input type="text" name="promote_price" value="0.00"/>元<br/>
                    开始时间:<input type="text" name="promote_start_date"  id="promote_start_date"/><br/>
                    结束时间:<input type="text" name="promote_end_date"  id="promote_end_date"/>
                </td>
            </tr>
            <tr>
                <td class="label3">是否新品：</td>
                <td>
                    <input type="radio" name="is_new" value="是" <if condition="$row.is_new eq 是"> checked </if> /> 是
                    <input type="radio" name="is_new" value="否" <if condition="$row.is_new eq 否"> checked </if> /> 否
                </td>
            </tr>
            <tr>
                <td class="label3">是否精品：</td>
                <td>
                    <input type="radio" name="is_best" value="是" <if condition="$row.is_best eq 是"> checked </if> /> 是
                    <input type="radio" name="is_best" value="否" <if condition="$row.is_best eq 否"> checked </if>/> 否
                </td>
            </tr>
            <tr>
                <td class="label3">是否热卖：</td>
                <td>
                    <input type="radio" name="is_hot" value="是" <if condition="$row.is_hot eq 是"> checked </if>/> 是
                    <input type="radio" name="is_hot" value="否" <if condition="$row.is_hot eq 否"> checked </if>/> 否
                </td>
            </tr>
            <tr>
                <td class="label3">推荐到楼层：</td>
                <td>
                    <input type="radio" name="is_floor" value="是" <if condition="$row.is_floor eq 是"> checked </if>/> 是
                    <input type="radio" name="is_floor" value="否" <if condition="$row.is_floor eq 否"> checked </if>/> 否
                </td>
            </tr>
            <tr>
                <td class="label3">加入推荐：</td>
                <td>
                    <input type="checkbox" name="is_best" value="1" <if condition="$row.is_best eq  是"> checked="true" </if> /> 精品
                    <input type="checkbox" name="is_new" value="1" <if condition="$row.is_new eq  是"> checked="true" </if> /> 新品
                    <input type="checkbox" name="is_hot" value="1" <if condition="$row.is_hot eq  是"> checked="true" </if> /> 热销
                </td>
            </tr>
            <tr>
                <td class="label3">推荐排序：</td>
                <td>
                    <input type="text" name="sort_order" size="5" value="{$row.sort_num}"/>
                </td>
            </tr>
            <tr>
                <td class="label3">市场售价：</td>
                <td>
                    <input type="text" name="market_price" value="{$row.market_price}" size="20" />
                </td>
            </tr>
            <tr>
                <td class="label3">商品关键词：</td>
                <td>
                    <input type="text" name="keywords" value="{$row.keywords}" size="40" /> 用空格分隔
                </td>
            </tr>
            <tr>
                <td class="label3">商品图片：</td>
                <td>
                    {$img}
                    <input type="file" name="logo" size="35" />
                </td>
            </tr>
            <!-- 商品描述 -->
            <table style="display: none" width="100%" class="tab_table" align="center">
                <tr>
                    <td>
                        <textarea name="goods_desc" id="goods_desc" cols="40" rows="3">{$row.goods_desc}</textarea>
                    </td>
                </tr>
            </table>

            <!-- 会员价格 -->
            <table style="display: none" width="90%" class="tab_table" align="center">
                <tr>
                    <td>
                        <p>
                            <foreach name="mlData" key="key" item="mlData_val">
                                <strong>{$mlData_val.level_name}</strong>
                                ￥<input type="text" value="<?php echo $mpData[$mlData_val['id']];?>" name="price[<?php echo $mlData_val['id']; ?>]" size = '8'/>元<br/><br/>
                            </foreach>
                        </p>
                    </td>
                </tr>
            </table>
            <!-- 商品属性 -->
    <table style="display: none" width="100%" class="tab_table" align="center">
        <tr>
            <td style="text-align: center">
                商品类型：<?php buildSelect('Type','type_id','id','type_name',$row['type_id'])?>
            </td>
        </tr>
        <tr>
        <td style="text-align: center">
            <ul id="attr_list">
            <?php
            $attId = array();
            foreach($gaData as $k => $v):
                    if(in_array($v['attr_id'],$attId)){
                    $opt = '-';
            }else{
                    $opt ='+';
                    $attId []= $v['attr_id'];
            }
            ?>
        <li>
            <input type="hidden" name="goods_attr_id[]" value="<?php echo $v['id']; ?>"/>
            <?php if($v[attr_type] == 'op'):?>
            <a onclick = "addNewAttr(this);" href="#">[<?php echo $opt; ?>]</a>
            <?php endif; ?>
            <?php echo $v['attr_name'] ?>
            <?php if($v['attr_option_values']):
            $attr = explode(',',$v['attr_option_values']);
            ?>
            <select name="attr_value[<?php echo $v['attr_id']?>][]">
                <option value="">请选择</option>
                <?php foreach($attr as $k1 =>$v1):
                if($v1 == $v['attr_value'])
                $select = 'selected = "selected "';
                else $select = '';
                ?>
                <option <?php echo $select; ?> value ="<?php echo $v1  ?>"><?php echo $v1?></option>
                <?php endforeach; ?>
            </select>
            <?php else: ?>
            <input type="text" name="" value="<?php echo $v['attr_value']?>"/>
            <?php endif; ?>
        </li>
            <?php endforeach; ?>
            </ul>
        </td>
        </tr>
    </table>
            <!-- 商品相册 -->
    <table style="display: none" width="100%" class="tab_table" align="center">
    <tr>
        <td>
            <input id ="btn_add_pic" type ="button" value="添加一张 "/>
            <hr/>
            <ul id="ul_pic_list"></ul>
            <hr/>
            <ul id="old_pic_list">
                <foreach name="gpData" item="gp_val">
                <li>
                    <input pic_id="{$gp_val.id}" class="btn_del_pic" type="button" value="删除"/><br/><br/>
                    {:showImage($gp_val['mid_pic'],150)}
                </li>
                    </foreach>
                </ul>
        </td>
    </tr>
    </table>
        </table>
        <div class="button-div">
            <input type="submit" value=" 确定 " class="button"/>
            <input type="reset" value=" 重置 " class="button" />
        </div>
    </form>
</div>
</div>
<link href="__PUBLIC__/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="__PUBLIC__/umeditor/third-party/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/umeditor/third-party/template.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/umeditor/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/umeditor/umeditor.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/umeditor/lang/zh-cn/zh-cn.js"></script>
<script>
    UM.getEditor('goods_desc',{
        initialFrameWidth :"100%",
        initialFrameHeight :350
    });
</script>
<script>
    $('#tabbar-div p span').click(function () {
        var i =$(this).index();
        $(".tab_table").hide();
        $(".tab_table").eq(i).show();
        $(".tab-front").removeClass('tab-front').addClass('tab-back');
        $(this).removeClass('tab-back').addClass('tab-front');
    });

    $("#btn_add_pic").click(function () {
        var file ="<li><input type='file' name='pic[]'/></li>"
        $("#ul_pic_list").append(file);
    })

    $(".btn_del_pic").click(function () {
        if(confirm("确定删除吗")){
            var li = $(this).parent();
            var pid =$(this).attr('pic_id');
            $.ajax({
                type:'GET',
                url:"<?php echo U('ajaxPicDel','',FALSE);?>/picid/" + pid,
                success:function (data) {
                    li.remove();
                }
            })
        }
    });

    //选择类型获取属性的AJAX
    $("select[name=type_id]").change(function () {
        //获取当前选择的ID
        var typeId = $(this).val();
        //如果选择了一个类型就执行AJAX属性
        if(typeId > 0){
            $.ajax({
                type: "GET",
                url: "<?php echo U('ajaxGetAttr','',FALSE)?>/type_id/"+typeId,
                dataType:'json',
                success:function (data) {
                    var li ="";
                    $(data).each(function (k,v) {
                        li+= '<li>';
                        if(v.attr_type =="op")
                            li +='<a onclick="addNewAttr(this);" href="#">[+]</a>';
                        li += v.attr_name + ' : ';
                        if(v.attr_option_values == "")
                            li +='<input type="text" name="attr_value['+ v.id +'][]"/>';
                        else{
                            li +='<select name="attr_value['+ v.id +'][]"><option value="">请选择</option>';
                            var _attr =v.attr_option_values.split(',');
                            for(var i=0;i<_attr.length;i++){
                                li += '<option value="'+_attr[i]+'">'
                                li += _attr[i];
                                li += '</option>';
                            }
                            li +='</select>';
                        }
                        li += '</li>'
                    });
                    $('#attr_list').html(li);
                }
            })
        }else{
            $('#attr_list').html("");
        }
    });
    function addNewAttr(a) {
        var li = $(a).parent();
        if($(a).text() == "[+]"){
            var newLi = li.clone();
            newLi.find("option:selected").removeAttr('selected');
            newLi.find("input[name='goods_attr_id[]']").val("");
            newLi.find("a").text('[-]');
            li.after(newLi);
        }
        else{
            var gaid = li.find("input[name='goods_attr_id[]']").val();
            if(gaid == ""){
                li.remove();
            }else{
                if(confirm('如果删除了这个属性，那么相关的库存量也会被一起删除，确定要删除吗')){
                 $.ajax({
                     type:'GET',
                     url:"<?php echo U('ajaxDelAttr?goods_id='.$row['id'],'',FALSE); ?>/gaid/" + gaid,
                     success: function (data) {
                         li.remove();
                     }
                 })
                }
            }
        }
    }
    function addNewCat() {
        $('#cat_list').append($('#cat_list').find('li').eq(0).clone());
    }
</script>

<script src="__PUBLIC__/Admin/Js/tron.js"></script>
<link href="__PUBLIC__/datetimepicker/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/datetimepicker/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/datetimepicker/datepicker-zh_cn.js"></script>
<link rel="stylesheet" media="all" type="text/css" href="__PUBLIC__/datetimepicker/time/jquery-ui-timepicker-addon.min.css" />
<script type="text/javascript" src="__PUBLIC__/datetimepicker/time/jquery-ui-timepicker-addon.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/datetimepicker/time/i18n/jquery-ui-timepicker-addon-i18n.min.js"></script>
<script>
    // 添加时间插件
    $.timepicker.setDefaults($.timepicker.regional['zh-CN']);  // 设置使用中文

    $("#promote_start_date").datetimepicker();
    $("#promote_end_date").datetimepicker();
</script>